<template>
  <div>
    <el-dialog title="绑定手机号"
               :close-on-click-modal="false"
               :visible.sync="visible"
               width="400px"
               :before-close="handleClose">
      <el-form ref="ruleForm"
               :model="ruleForm"
               :rules="rules"
               label-width="70px">
        <el-form-item label="手机号"
                      prop="mobile">
          <el-input v-model="ruleForm.mobile"
                    placeholder="手机号"
                    @input="changeMobile" />
        </el-form-item>
        <el-form-item prop="code"
                      label="验证码">
          <div class="item-flex">
            <el-input v-model="ruleForm.code"
                      type="text"
                      placeholder="验证码">
            </el-input>
            <el-button v-if="isshowMsgCode"
                       :disabled="sendDisabled"
                       @click="handleSend">发送验证码</el-button>
            <el-button v-if="!isshowMsgCode"
                       disabled>{{ showTime }}秒后重新发送</el-button>
          </div>
          <div class="text">{{ frequency }}</div>
        </el-form-item>
      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary"
                   @click="affirmative">确 定</el-button>
      </span>
    </el-dialog>
    <!-- <el-dialog top="32vh"
               append-to-body
               width="480px"
               :visible.sync="pictureShow"
               :close-on-click-modal="false">
      <div slot="title">完成拼图验证</div>
      <div v-if="pictureShow"
           class="authen-show">
        <authentication :on-success="success"
                        :on-syntony="picture"
                        width="260"
                        height="120"
                        pl-size="30"
                        deviation="5"
                        :puzzle-img-list="imgLists"
                        class="auth-entication-style"
                        @fatherMethod="pictureShow = false" />
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
// import AppendToBodyModle from './AppendToBody.vue';

export default {
  name: 'BindMobile',
  model: {
    prop: 'visible',
    event: 'close'
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      ruleForm: {},
      rules: {
        mobile: [{ required: true, message: '请输入手机号', trigger: 'blur' }, {
          pattern: /^[1][3,4,5,6,7,8,9][0-9]{9}$/,
          message: "请输入正确的手机号码格式"
        }],
        code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      },
      isshowMsgCode: true,
      sendDisabled: true,
      showTime: null,
      frequency: "",
    }
  },
  methods: {
    sendOutTime () {
      this.isshowMsgCode = false;
      this.showTime = 60;
      const authTimeTimer = setInterval(() => {
        this.showTime--;
        if (this.showTime <= 0) {
          this.isshowMsgCode = true;
          clearInterval(authTimeTimer);
        }
      }, 1000);
    },
    changeMobile (value) {
      let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
      if (reg.test(value)) {
        this.sendDisabled = false
      } else {
        this.sendDisabled = true
      }
    },
    handleClose () {
      this.$emit('close', false)
    },
    handleSend () {
      this.pictureShow = true
    },
    affirmative () {
      this.$emit('affirmat')
    }
  }
}
</script>

<style scoped>
.item-flex {
  display: flex;
}
</style>